var isAdmin = false;
var user_status_color = "transparent";
function doConfirm(event) {
    switch (event["type"]) {
        case "connect"://连接确认
            connection_socketID = event["socketID"];
            switch (event["status"]) {
                case 100://用户登录成功
                    $("#userConnect").hide();
                    console.log("<用户> 用户登录成功");
                    $("#welcome").text("等待服务器响应...");
                    identify = event["identify"];
                    if (event["identify"] >= 7) { isAdmin = true; console.log("<用户> 管理员身份已确认"); successBox("管理员身份确认成功"); }
                    else { isAdmin = false; }
                    $("#welcome").text("欢迎回来, " + username);
                    break;
                case 105://用户注册成功
                    console.log("<用户> 用户注册成功");
                    $("#userConnect").hide();
                    $("#welcome").show();
                    $("#welcome").text("欢迎加入, " + username);
                    break;
            }
            if (getCookie("fastLoad", parse = true)) {
                $("#register-or-login").remove();
            } else {
                // if(Math.floor(Math.random()*10) <=4) OKAIRI.play();
                // else OTSUKARE.play();
                $("#register-or-login").fadeOut(1000, function () {
                    $("#register-or-login").remove();
                });
            }
            $("#header").slideDown(1000);
            $("#side-username").html(username);
            $("#profile-photo").attr("src", '/chat/static/images/head/' + event["userID"] + ".ico");
            let user_status_color_choose = document.createElement('div'),
                user_status_text = document.createElement('span');
            user_status_text.style = "line-height: 100%;vertical-align: middle;";
            user_status_color_choose.id = "user-status-color";
            user_status_text.id = "user-status-text";
            document.getElementById("user-status").appendChild(user_status_color_choose);
            document.getElementById("user-status").appendChild(user_status_text);
            setCookie("fastLoad", true, 60, false);
            if (localStorage.length !== 6) {
                if (localStorage.length === 0) {
                    ws.send(JSON.stringify({ "action": "get-status-icons", "username": username }));
                }
                // ws.send(JSON.stringify({ "action": "get-status-icons","icon-name": }));
            } else {
                status_icon_recv_ok = true;
                status_icon_recv.update(localStorage.length);
            }
            switch (event["user-status"]) {
                case 120:
                    user_status = "online";
                    user_status_color = "green";
                    user_status_color_choose.style = "background-color:rgb(0,255,0);width:16px;height:16px;border-radius:50%;";
                    user_status_text.innerHTML = "在线";
                    break;
                case 121:
                    user_status = "busy";
                    user_status_color = "yellow";
                    user_status_color_choose.style = "background-color:rgb(255,255,0);width:16px;height:16px;border-radius:50%;";
                    user_status_text.innerHTML = "忙碌";
                    break;
                case 122:
                    user_status = "leave";
                    user_status_color = "red";
                    user_status_color_choose.style = "background-color:rgb(255,0,0);width:16px;height:16px;border-radius:50%;";
                    user_status_text.innerHTML = "离开";
                    break;
                case 123:
                    user_status = "hidden";
                    user_status_color = "gray";
                    user_status_color_choose.style = "background-color:rgb(100,100,100);width:16px;height:16px;border-radius:50%;";
                    user_status_text.innerHTML = "隐身";
                    break;
            }
            if (isAdmin) {
                $("#side-userIdentify").html($("#side-userIdentify").html() + "<span>等级: " + identify + '</span><span style="color:rgb(255,215,0)">管理员</span>');
            } else {
                $("#side-userIdentify").html($("#side-userIdentify").html() + "<span>等级: " + identify + '</span>');
            }
            break;
        case "recallMsg"://撤回消息
            $("#" + event["id"]).css("color", "gray");
            $("#" + event["id"]).html(event["recallUsername"] + "撤回了一条消息");
            $("#" + event["id"]).slideUp(1000, function () {
                $("#" + event["id"]).remove();
            });
            break;
        case "redirect": //重定向
            if (event["status"] === 300) {
                var curPATH = window.location.href,
                    PATHname = window.document.location.pathname,
                    pos = curPATH.indexOf(PATHname);
                if (event["search"]) window.location.href = curPATH.substring(0, pos) + event["target"] + "?" + event["search"];
                else window.location.href = curPATH.substring(0, pos) + event["target"];
            }
            break;
        case "status-icon"://图标传输
            if (event["name"] === "end") {
                status_icon_recv_ok = true;
                return true;
            }
            localStorage.setItem(event["name"], "data:image/*;base64," + event["data"]);
            console.log("<存储> 获取" + event["name"] + "成功");
            status_icon_recv.update();
            break;
        case "debug"://debug模式,打印所有接收信息
            console.log(event["message"]);
            break;
        }
}